﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TMDT_Nhom1A.DTO;
using TMDT_Nhom1A.BUS;

namespace TMDT_Nhom1A
{
    public static class MyCookie
    {
        public static List<MyOrderProduct_Online> ReadCookie(string detailCart)
        {
            List<MyOrderProduct_Online> listoderproduct_online = new List<MyOrderProduct_Online>();
            string[] listDetailCart = detailCart.Split('/');
            MyOrderProduct_Online sd = new MyOrderProduct_Online();
            for (int i = 0; i < listDetailCart.Length; i++)
            {
                string[] temp = listDetailCart[i].Split(',');
                var list = ElectricDevice_BUS.DetailElectricDevice(temp[0]);
                if (list.Count > 0)
                {
                    MyOrderProduct_Online myorderproduct = new MyOrderProduct_Online();
                    myorderproduct.ElectricDeviceID = list[0].ElectricDevice_ID;
                    myorderproduct.ElectricDeviceName = list[0].ElectricDevice_Name;
                    myorderproduct.DealerPrice = decimal.Parse(list[0].DealerPrice);
                    myorderproduct.RetailPrice = decimal.Parse(list[0].RetailPrice);
                    myorderproduct.Quantity = int.Parse(temp[1]);
                    string NonDiscountPrice = "";
                    string DiscountPrice = "";
                    Coupon_BUS.GetPriceCouponOfElectricDevice(temp[0], ref NonDiscountPrice, ref DiscountPrice);
                    if (NonDiscountPrice != "")
                    {
                        myorderproduct.PriceCoupon = decimal.Parse(NonDiscountPrice);
                    }
                    else
                    {
                        myorderproduct.PriceCoupon = 0;
                    }

                    if (myorderproduct.PriceCoupon == 0)
                    {
                        if (myorderproduct.Quantity < 10)
                            myorderproduct.TotalPrice = myorderproduct.Quantity * myorderproduct.RetailPrice;
                        else
                            myorderproduct.TotalPrice = myorderproduct.Quantity * myorderproduct.DealerPrice;

                    }
                    else
                    {
                        myorderproduct.TotalPrice = myorderproduct.Quantity * myorderproduct.PriceCoupon;
                    }

                    listoderproduct_online.Add(myorderproduct);
                }
            }
            return listoderproduct_online;
        }
    }
}
